package ro.xblue.translator;

import java.util.Hashtable;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import ro.gateway.aida.db.PersistenceManager;
import ro.gateway.aida.db.PersistenceToken;
import ro.gateway.aida.servlet.Constants;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: CopyFilesToDB.java,v 1.1 2004/10/24 23:37:02 mihaipostelnicu Exp $
 *
 * deprecated
 */
public class CopyFilesToDB extends Action
{
      public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response )
            throws Exception
      {
            ServletContext application = getServlet().getServletContext();
            Hashtable services = ( Hashtable ) application.
                  getAttribute( Constants.SERVICES );
            PersistenceToken token = PersistenceManager.tokenLookup( application );


//            File dir = new File( getServlet().
//                  getServletContext().getRealPath( "/WEB-INF/translator" ) );
//            if ( !dir.exists() )
//            {
//                  return mapping.findForward( "finnish" );
//            }
//
//            Translator translator = new Translator( dir );
//            try
//            {
//                  TranslatorDBAccessor.getManager( token ).delete_all();
//
//                  String[] modules = translator.getModuleNames();
//                  if ( modules != null )
//                  {
//                        for ( int i = 0; i < modules.length; i++ )
//                        {
//                              Module mod = translator.getModule( modules[ i ] );
//                              String langs[] = mod.getAvailableLangs();
//                              if ( langs != null )
//                                    for ( int j = 0; j < langs.length; j++ )
//                                    {
//                                          Properties props = mod.getMessages( langs[ j ] );
//                                          Enumeration en = props.keys();
//                                          while ( en.hasMoreElements() )
//                                          {
//                                                String key = ( String ) en.nextElement();
//                                                String value = props.getProperty( key );
//                                                TransItem item = new TransItem();
//                                                item.setModule( modules[ i ] );
//                                                item.setLang( langs[ j ] );
//                                                item.setLabel( key );
//                                                item.setText( value );
//                                                TranslatorDBAccessor.getManager( token ).insert( item );
//                                          } // messages
//                                    } // languages
//                        } // for modules
//                  } // if modules != null
//            } //try
//            catch ( Exception ex )
//            {
//                  ex.printStackTrace();
//            }

            return mapping.findForward( "finnish" );
      }
}
